home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / MIDPNT.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-29  |  726b  |  30 lines

  1. PROCEDURE midpnt(a,b: real; VAR s: real; n: integer);
  2. (* Programs using routine MIDPNT must supply a function
  3. func(x:real):real which is to be integrated. They must also
  4. declare an iteration counter
  5. VAR
  6.    glit: integer; *)
  7. VAR
  8.    j: integer;
  9.    x,tnm,sum,del,ddel: real;
  10. BEGIN
  11.    IF  (n = 1)  THEN BEGIN
  12.       s := (b-a)*func(0.5*(a+b));
  13.       glit := 1
  14.    END ELSE BEGIN
  15.       tnm := glit;
  16.       del := (b-a)/(3.0*tnm);
  17.       ddel := del+del;
  18.       x := a+0.5*del;
  19.       sum := 0.0;
  20.       FOR j := 1 TO glit DO BEGIN
  21.          sum := sum+func(x);
  22.          x := x+ddel;
  23.          sum := sum+func(x);
  24.          x := x+del
  25.       END;
  26.       s := (s+(b-a)*sum/tnm)/3.0;
  27.       glit := 3*glit
  28.    END
  29. END;
  30.